package com.rtwo.repository;

import com.rtwo.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * Created by hasee on 2017/4/19.
 */
@Repository
public interface RoleRepository extends JpaRepository<Role,Long>{

    @Query(value="select lv from role r where r.name=?1",nativeQuery = true)
    long getLvByName(String name);

    @Query(value="insert into role(name,lv) values(?1,?2)",nativeQuery = true)
    @Modifying
    void insertName(String name,long lv);

    @Query(value="update role r set r.lv=?2 where r.name=?1",nativeQuery = true)
    @Modifying
    void updateName(String name,long lv);

    @Query(value="delete from role where id=?1",nativeQuery = true)
    @Modifying
    void deleteById(long lv);

    @Query(value="select d.name from role r,Department d where d.id=?1",nativeQuery = true)
    String getDepById(long id);

}
